#include "GtrAlgorithm.h"


GtrAlgorithm::GtrAlgorithm(list<Request> requests)
{
	this->requests = requests;
}

GtrAlgorithm::~GtrAlgorithm()
{
	delete [] actual_coords;
}

list<Request> GtrAlgorithm::calculate() {
	list<Request>::iterator itr_start;
	list<Request>::iterator itr_end_visible;
	list<Request>::iterator itr_nearest_req;
	actual_position = requests.begin();
	while (requests.size()!=0) {
		itr_start = requests.begin();
		itr_end_visible = OLTSPInstance::get_visible_requests(requests.begin(), requests.end(), actual_time);
		if (itr_start == itr_end_visible)
			actual_time = itr_start->release_time;
		else {
			itr_nearest_req = OLTSPInstance::nearest_request(itr_start, itr_end_visible, *actual_position);
			actual_time += (itr_nearest_req->get_distance(*actual_position))/(speed);
			itr_nearest_req->visited_time = actual_time;
			requests_done.push_back(*itr_nearest_req);
			requests.remove(*itr_nearest_req);

		}
	}
	return requests_done;
}



